﻿import QtQuick 2.0

Item {


    function paint_pixels(image, padding,  width,  height,  time)
    {
        var halfh = padding + (height - padding * 2) / 2;
        var halfw = padding + (width  - padding * 2) / 2;
        var ir, or;
//        uint32_t *pixel = image;
        var y;

        /* squared radii thresholds */
        or = (halfw < halfh ? halfw : halfh) - 8;///?
        ir = or - 32;///?
        or *= or;
        ir *= ir;

//        pixel += padding * width;
        var yLine = new Array
        for (y = padding; y < height - padding; y++) {
            var x;
            var y2 = (y - halfh) * (y - halfh);

            pixel += padding;
            for (x = padding; x < width - padding; x++) {
                var v;
                var xLine = new Array

                /* squared distance from center */
                var r2 = (x - halfw) * (x - halfw) + y2;

                if (r2 < ir)
                    v = (r2 / 32 + time / 64) * 0x0080401;
                else if (r2 < or)
                    v = (y + time / 32) * 0x0080401;
                else
                    v = (x + time / 16) * 0x0080401;///color
                v &= 0x00ffffff;

                /* cross if compositor uses X from XRGB as alpha */
                if (abs(x - y) > 6 && abs(x + y - height) > 6)
                    v |= 0xff000000;

                xLine.append(v)
//                *pixel++ = v;
            }

            yLine.append(xLine)

//            pixel += padding;
        }

        return yLine
    }

    Component.onCompleted: {
        var result = paint_pixels("image", 0,  100,  100,  0)
        console.log(result.length)
        for(var i =0; i<result.length; i++){
            var resultB = result[i]
            for(var j=0; j<resultB.length; j++){
                console.log(resultB[j])
            }
        }
    }
}
